package com.ellricky.baselib.adapter.cla

import android.app.Activity
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.andr.common.ui.adapter.BaseRecyclerAdapter
import com.andr.common.ui.adapter.SmartViewHolder
import com.andr.common.util.EmptyUtil
import com.andr.common.util.ViewUtil
import com.ellricky.baselib.R
import com.ellricky.baselib.entity.cla.ClassStuEntity
import com.ellricky.baselib.entity.cla.ClassTcEntity
import com.ellricky.baselib.entity.new.StudentEntry
import com.ellricky.baselib.entity.new.TeacherEntry
import com.ellricky.baselib.listener.OnModifyListener
import com.ellricky.baselib.util.GlideUtil
import de.hdodenhof.circleimageview.CircleImageView

class StuModifyAdapter(val act: Activity, val rvType: Int, val listener: OnModifyListener) :
    BaseRecyclerAdapter<StudentEntry>(R.layout.base_adapter_class_person_modify) {

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: StudentEntry, position: Int) {
        vh?.let {

            val flAvatar = it.itemView.findViewById<FrameLayout>(R.id.flAvatar)

            val ivAdd = it.itemView.findViewById<ImageView>(R.id.ivAdd)

            val ivAvatar = it.itemView.findViewById<CircleImageView>(R.id.cvAvatar)
            val ivDel = it.itemView.findViewById<ImageView>(R.id.ivDel)
            val tvName = it.itemView.findViewById<TextView>(R.id.tvName)

            when (p1.member_state) {
                "6" -> {//请假
                    tvName.setTextColor(ContextCompat.getColor(act, R.color.orange))
                }
                "7" -> {//旷课
                    tvName.setTextColor(ContextCompat.getColor(act, R.color.khaki))
                }
                else->{
                    tvName.setTextColor(ContextCompat.getColor(act, R.color.common_main_black))
                }
            }
            val needAdd = EmptyUtil.isEmpty(p1.member_id)
            when (needAdd) {
                true -> {
                    ivAvatar.visibility = View.GONE
                    tvName.visibility = View.INVISIBLE
                    ivAdd.visibility = View.VISIBLE
                }
                false -> {
                    ivAvatar.visibility = View.VISIBLE
                    tvName.visibility = View.VISIBLE
                    ivAdd.visibility = View.GONE

                    GlideUtil.into(act, p1.member_head, ivAvatar)
                    tvName.text = p1.member_name
                }
            }

            flAvatar.setOnClickListener {
                if (ViewUtil.isFastDoubleClick()) return@setOnClickListener
                if (needAdd)
                    listener.jumpStuAdd(rvType, position, p1.sortNo ?: "")
                else
                    listener.changeStatePerson(rvType, position, p1.member_id ?: "")
            }
        }
    }
}


class TcModifyAdapter(val act: Activity, val rvType: Int, val listener: OnModifyListener) :
    BaseRecyclerAdapter<TeacherEntry>(R.layout.base_adapter_class_person_modify) {

    override fun onBindViewHolder(vh: SmartViewHolder?, p1: TeacherEntry?, position: Int) {
        vh?.let {
            val flAvatar = it.itemView.findViewById<FrameLayout>(R.id.flAvatar)

            val ivAdd = it.itemView.findViewById<ImageView>(R.id.ivAdd)

            val ivAvatar = it.itemView.findViewById<CircleImageView>(R.id.cvAvatar)
            val ivDel = it.itemView.findViewById<ImageView>(R.id.ivDel)
            val tvName = it.itemView.findViewById<TextView>(R.id.tvName)

            val needAdd = EmptyUtil.isEmpty(p1?.teacher_id)
            when (needAdd) {
                true -> {
                    ivAvatar.visibility = View.GONE
                    ivDel.visibility = View.GONE
                    tvName.visibility = View.INVISIBLE
                    ivAdd.visibility = View.VISIBLE
                }
                false -> {
                    ivAvatar.visibility = View.VISIBLE
                    ivDel.visibility = View.VISIBLE
                    tvName.visibility = View.VISIBLE
                    ivAdd.visibility = View.GONE

                    ivAvatar.setImageResource(R.drawable.base_icon_person_add_default)
                    tvName.text = p1?.teacher_name
                }
            }

            flAvatar.setOnClickListener {
                if (ViewUtil.isFastDoubleClick()) return@setOnClickListener
                if (needAdd)
                    listener.jumpTcAdd(rvType, position, p1?.sort_no ?: "")
                else
                    listener.changeStatePerson(rvType, position, p1?.teacher_id ?: "")
            }

        }
    }
}